package com.diudiutechnology.www.yadiudiu.yadiudiu.house.MyAdapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.diudiutechnology.www.yadiudiu.yadiudiu.model.BuyACarFragmentModel;
import com.diudiutechnology.www.yadiudiu.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/8/15.
 * 购房
 */

public class HousePurchaseFragmentAdapter extends BaseAdapter {

    private Context mContext;
    private  int countday=0;
    List<BuyACarFragmentModel> model= new ArrayList<>();
    public HousePurchaseFragmentAdapter(Context context) {
        this.mContext = context;
    }

    @Override
    public int getCount() {
        return model.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    public void addItem( List<BuyACarFragmentModel> model,int countday){
        this.countday=countday;
        this.model=model;
        notifyDataSetChanged();
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.item_house, null);
            holder.item_image = (ImageView) convertView
                    .findViewById(R.id.item_image);
            holder.item_title = (TextView) convertView
                    .findViewById(R.id.item_title);

            holder.item_site = (TextView) convertView
                    .findViewById(R.id.item_site);
            holder.distance = (TextView) convertView
                    .findViewById(R.id.distance);
            holder.tingshi = (TextView) convertView
                    .findViewById(R.id.tingshi);
            holder.item_moneys = (TextView) convertView
                    .findViewById(R.id.item_moneys);


            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.item_image.setImageResource(R.mipmap.imhouse);
        BuyACarFragmentModel bModel = model.get(position);

        holder.item_title.setText(bModel.getName());

        holder.item_site.setText(bModel.getLet());
        holder.item_moneys.setText(bModel.getMoney1());
        holder.distance.setText(bModel.getDistance());
        holder.tingshi.setText(bModel.getDate());

        return convertView;
    }

    class ViewHolder {
        ImageView item_image;
        TextView item_title;

        TextView item_site;
        TextView distance;
        TextView tingshi;
        TextView item_moneys;

    }
}

